package com.ricky04.web;


import org.springframework.boot.web.embedded.jetty.JettyServletWebServerFactory;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.server.*;
import org.springframework.boot.web.servlet.ServletContextInitializer;
import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory;
import org.springframework.boot.web.servlet.server.Jsp;
import org.springframework.boot.web.servlet.server.Session;
import org.springframework.context.annotation.Bean;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;

import java.io.File;
import java.net.InetAddress;
import java.nio.charset.Charset;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;

/**
 * 定制server相关配置
 * 比如端口 context等都能
 *
 * 除了这种 还可以通过创建bean的方式
 */
@Component
public class MyEmbeededServletCOntainerCustomizer implements WebServerFactoryCustomizer<ConfigurableServletWebServerFactory> {
    @Override
    public void customize(ConfigurableServletWebServerFactory server) {
        server.setDisplayName("rickydemo");
        server.setPort(80);
        System.out.println("-----"+server.getClass());
        JettyServletWebServerFactory jetty=(JettyServletWebServerFactory)server;
//        TomcatServletWebServerFactory tomcat=(TomcatServletWebServerFactory)server;
//        tomcat.setBaseDirectory(new File("E:/tmp/tomcat"));

    }

    /**
     * 方法二
     */
//    @Bean
    public ConfigurableServletWebServerFactory createServer(){
        TomcatServletWebServerFactory factory=new TomcatServletWebServerFactory() ;
        factory.setDisplayName("rickydemo2");
        factory.setPort(80);
        factory.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND,"/404.html"));
        return factory;
    }

}
